#ifndef HITTABLE_LIST_H
#define HITTABLE_LIST_H


#include<vector>


#include"hittable.h"




class hittable_list :public hittable {
public: 
	
	std::vector<shared_ptr<hittable>> objects;

	hittable_list(){}
	hittable_list(shared_ptr<hittable> object) { add(object); }

	void clear() { objects.clear(); }

	void add(shared_ptr<hittable> object) {
		objects.push_back(object);
	}

	bool hit(const ray& _ray, interval ray_t, hit_record& rec) const override {
		hit_record temp_rec;
		bool is_hit = false;
		auto closet_cur = ray_t.max;

		for (const auto& obj : objects) {
			if (obj->hit(_ray, interval(ray_t.min,closet_cur), temp_rec)) {
				is_hit = true;
				closet_cur = temp_rec.t;//update closest hitted object
				rec = temp_rec;
			}
		}

		return is_hit;

	}

};



#endif // !HITTABLE_LIST_H

